package com.zzyl.common.utils;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;

import java.io.IOException;
import java.io.InputStream;

public class PDFUtil {

    public static String pdfToString( InputStream inputStream ) throws IOException {

        PDDocument document = null;

        try {
            document = PDDocument.load(inputStream);

            PDFTextStripper pdfStripper = new PDFTextStripper();

            String text = pdfStripper.getText(document);

            return text;
        }catch( IOException e ) {
            e.printStackTrace();
        }finally {
            if( document != null ){
                document.close();
                inputStream.close();
            }
        }
    return null;
    }
}
